package com.ats.developer.components.field
{
	import com.ats.developer.components.FormItem;
	import com.ats.developer.components.borderpint.BBorderPoint;
	import com.ats.developer.components.borderpint.BRBorderPoint;
	import com.ats.developer.components.borderpint.LBBorderPoint;
	import com.ats.developer.components.borderpint.LBorderPoint;
	import com.ats.developer.components.borderpint.RBorderPoint;
	import com.ats.developer.components.borderpint.TBorderPoint;
	import com.ats.developer.components.borderpint.TLBorderPoint;
	import com.ats.developer.components.borderpint.TRBorderPoint;
	import com.soso.module.Product;
	
	import flash.events.Event;
	
	import mx.containers.Canvas;
	import mx.controls.Image;
	import mx.controls.Label;
	import mx.controls.Text;
	
	public class ATSImg extends FormItem
	{	
		public var tb:TBorderPoint=new TBorderPoint(0,0);
		public var bb:BBorderPoint=new BBorderPoint(0,0);
		public var rb:RBorderPoint=new RBorderPoint(0,0);
		public var lb:LBorderPoint=new LBorderPoint(0,0);
		public var tlb:TLBorderPoint=new TLBorderPoint(0,0);
		public var lbb:LBBorderPoint=new LBBorderPoint(0,0);
		public var trb:TRBorderPoint=new TRBorderPoint(0,0);
		public var brb:BRBorderPoint=new BRBorderPoint(0,0);
		public var img:Image=new Image();
		public var index:Label=new Label();
		[Bindable]
		private var _product:Product;
		
		[Bindable]
		public var protation:Number=0;
		[Bindable]
		public var pzoom:Number;
		[Bindable]
		public var pbright:Number=0;
		[Bindable]
		public var pcontrast:Number=0;
		
		
		public function ATSImg(){
			super();
		}
		
		public function get product():Product
		{
			return _product;
		}

		public function set product(value:Product):void
		{
			_product = value;
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			rb.update(unscaledWidth,unscaledHeight);
			lb.update(unscaledWidth,unscaledHeight);
			tb.update(unscaledWidth,unscaledHeight);
			bb.update(unscaledWidth,unscaledHeight);
			tlb.update(unscaledWidth,unscaledHeight);
			lbb.update(unscaledWidth,unscaledHeight);
			trb.update(unscaledWidth,unscaledHeight);
			brb.update(unscaledWidth,unscaledHeight);
			
			img.width=unscaledWidth;
			img.height=unscaledHeight;
			
//			index.width=unscaledWidth/3;
			trace("update: "+unscaledWidth+" "+unscaledHeight);
			trace(rb.x+" "+rb.y);
			index.graphics.clear();
			index.graphics.beginFill(0xFFFFFF,0.6);
			index.graphics.drawCircle(index.width/2,index.height/2,12);
			index.graphics.endFill();
//			index.graphics.beginFill(0xFFFFFF);
//			index.graphics.drawRect(0,0,index.width,index.height);
//			index.graphics.endFill();
			
			pzoom=Math.round(this.img.contentWidth/this.real_width*100);
		}
		public var canvas:Canvas=new Canvas();
		override protected function createChildren():void{
			super.createChildren();
			canvas.horizontalScrollPolicy="off";
			canvas.verticalScrollPolicy="off";
			this.horizontalScrollPolicy="off";
			this.verticalScrollPolicy="off";
			index.setStyle("fontFamily","myverdana");
			index.setStyle("fontSize","16");
			index.setStyle("textAlign","center");
			index.bottom=0;
			index.right=0;
			index.graphics.clear();
			index.graphics.beginFill(0xFFFFFF);
			index.graphics.drawRect(0,0,index.width,index.height);
			index.graphics.endFill();
			index.visible=false;
//			img.width=100;
//			img.height=100;
			img.addEventListener(Event.COMPLETE,img_Complete);
			canvas.addChild(img);
			canvas.addChild(index);
			this.add(canvas);
//			this.add(img);
			this.add(rb);
			this.add(lb);
			this.add(tb);
			this.add(bb);
			this.add(tlb);
			this.add(lbb);
			this.add(trb);
			this.add(brb);
		}
		
		public var real_width:Number;
		public var real_height:Number;
		protected function img_Complete(event:Event):void{
			real_width = img.contentWidth;
			real_height = img.contentHeight;
			this.img.width = img.contentWidth;
			this.img.height = img.contentHeight;
			this.width = img.contentWidth;
			this.height = img.contentHeight;
			pzoom=this.img.width/this.real_width*100;
		}
	}
}
